package com.imti.mall.sale.mapper;

import com.imti.mall.model.sms.pojo.SmsHomeRecommendProduct;
import com.imti.mall.model.sms.pojo.SmsHomeRecommendSubject;
import org.apache.ibatis.jdbc.SQL;

public class SmsHomeRecommendSubjectMapper {
    /**
     * 查询首页专题推荐表
     */
    public String findSmsHomeRecommendSubject(final SmsHomeRecommendSubject smsHomeRecommendSubject){
        return new SQL(){
            {
                SELECT(" id,subject_id,subject_name,recommend_status,sort");
                FROM(" sms_home_recommend_subject");
                StringBuffer sb=new StringBuffer();
                if(smsHomeRecommendSubject!=null){

                    if(smsHomeRecommendSubject.getSubjectId()!=null){
                        sb.append(" and subject_id=#{subjectId}");
                    }

                    if(smsHomeRecommendSubject.getRecommendStatus()!=null){
                        sb.append(" and recommend_status=#{recommendStatus}");
                    }

                    if(smsHomeRecommendSubject.getSubjectName()!=null){
                        sb.append(" and subject_name LIKE concat('%',#{subjectName},'%')");
                    }

                }
                WHERE(" 1=1 "+sb.toString());
                ORDER_BY("sort desc");
            }
        }.toString();
    }


    /**
     * 修改首页专题推荐表
     * @param smsHomeRecommendSubject
     * @return
     */
    public String updateSmsHomeRecommendSubject(final SmsHomeRecommendSubject smsHomeRecommendSubject){
        return new SQL(){
            {
                UPDATE(" sms_home_recommend_subject ");
                if(smsHomeRecommendSubject.getSubjectId()!=null){
                    SET(" subject_id=#{subjectId} ");
                }
                if(smsHomeRecommendSubject.getSubjectName()!=null){
                    SET(" subject_name=#{subjectName} ");
                }
                if(smsHomeRecommendSubject.getRecommendStatus()!=null){
                    SET(" recommend_status=#{recommendStatus} ");
                }
                if(smsHomeRecommendSubject.getSort()!=null){
                    SET("  sort=#{sort}");
                }

                WHERE(" id=#{id} ");
            }
        }.toString();
    }
}
